import { _decorator, Component, Node, Prefab, CCFloat } from 'cc';
import { OBJ_TYPE } from '../../constant';
import { buildingCtrl } from '../buildingCtrl';
import { Cannon } from '../defense/Cannon/Cannon';
import { enemyBase } from '../enemyBase';
import { playerBase } from '../playerBase';
const { ccclass, property } = _decorator;

@ccclass('enemySkillBase')
export class enemySkillBase extends Component {
    @property({ type: Prefab, displayName: "碰撞动画预制体" })
    protected hitNode: Prefab = null;


    @property({ type: CCFloat, displayName: "默认伤害" })
    public hitNum: number = 5;

    public howHit: Node = null
    start() {

    }
    protected hit(other: Node) {
        if (!this.howHit) {
            console.log("没有找到谁");

            return
        }
        const ts: playerBase = other.getComponent(playerBase) as playerBase
        const ts2: enemyBase = other.getComponent(enemyBase) as enemyBase
        const ts3: buildingCtrl = other.getComponent(buildingCtrl) as buildingCtrl
        if (ts) {

            if (this.howHit.getComponent(enemyBase).obj_type == OBJ_TYPE.friendly) {
                //是友军打的不掉血
                return
            }
            ts.hit(this.hitNum, this.howHit)




        } else if (ts2) {
            if (this.howHit.getComponent(enemyBase).obj_type == ts2.obj_type) {
                //是友军打的不掉血
                return
            }
            ts2.hit(this.hitNum, this.howHit)


        } else if (ts3) {
            if (this.howHit.getComponent(Cannon)) {


                //如果是炮塔打到建筑物不掉血
                return
            }
            if (this.howHit.getComponent(enemyBase).obj_type == OBJ_TYPE.friendly) {
                //是友军打的不掉血
                return
            }
            ts3.hit(this.hitNum)


        }
    }
    update(deltaTime: number) {

    }
}


